import { ResultData } from "@/api/interface/index";
import { BASE } from "@/api/config/servicePort";
import http from "@/api";

/**
 * @name 用户管理模块
 */

// 获取列配置
export const getColumns = () => {
  return http.get<ResultData>(BASE + `/system/list_field/asset/`);
};

// 获取基础列（所有列）
export const getBaseColumns = () => {
  return http.get<ResultData>(BASE + `/field/asset/attrs/`);
};

// 获取资产列表
export const getCollect = (params: { page: number; page_size: number }) => {
  return http.get<ResultData>(BASE + `/asset/`, params);
};

// 获取搜索配置
export const getFilterElements = () => {
  return http.get<ResultData>(BASE + `/asset/filter_elements/`);
};

// 删除资产列表
export const deleteAssetList = id => {
  return http.delete(BASE + `/asset/${id}/`);
};

// 列表
export const getBaseDataList = () => {
  return http.get<any>(BASE + `/asset_base_data/`);
};

// 获取资产类型树
export const getAssetCollect = (params?) => {
  return http.get<any>(BASE + `/asset_type/`, params);
};

// 创建资产
export const create = data => {
  return http.post<any>(BASE + `/asset/`, data);
};

// 更新资产
export const update = (data, id) => {
  return http.patch<any>(BASE + `/asset/${id}/`, data);
};

// 获取详情
export const getDetail = id => {
  return http.get<any>(BASE + `/asset/${id}/`);
};

// 获取维护记录
export const getUpholdData = id => {
  return http.get<any>(BASE + `/asset/${id}/maintenance/`);
};

// 新建维护记录
export const createUphold = (id, data) => {
  return http.post<any>(BASE + `/asset/${id}/maintenance/`, data);
};

// 上传文件
export const uploadFile = (data: FormData) => {
  return http.post<any>(BASE + `/file/`, data, { cancel: false });
};

// 删除分组列表
export const deleteGroupTerminate = id => {
  return http.delete<ResultData>(BASE + `/asset_type/${id}/`);
};

// 创建分组
export const groupSpawn = data => {
  return http.post<any>(BASE + `/asset_type/`, data);
};

// 更新分组
export const groupModify = (data, uuid) => {
  return http.put<any>(BASE + `/asset_type/${uuid}/`, data);
};
